#pragma once
#include <pthread.h>
using namespace std;

class Lock
{
public:
    Lock(pthread_mutex_t* lock)
        :_lock(lock)
    {}
    ~Lock(){}
    inline int lock()
    {
        return pthread_mutex_lock(_lock);
    }
    inline int unlock()
    {
        return pthread_mutex_unlock(_lock);
    }

private:
    pthread_mutex_t* _lock;
};

class lockguard
{
public:
    lockguard(pthread_mutex_t* lock)
        :_mutex(lock)
    {
        _mutex.lock();
    }
    ~lockguard()
    {
        _mutex.unlock();
    }

private:
    Lock _mutex;
};